using System;
using UnityEngine;
using UnityEngine.UI;

public class BombButton : MonoBehaviour
{
	[SerializeField]
	private Image m_image;

	[SerializeField]
	private GameObject m_activePointer;

	[SerializeField]
	private Text m_bombsCountField;

	[SerializeField]
	private Text m_bombsCountFieldCopy;

	[SerializeField]
	private GameObject m_plus;

	[SerializeField]
	private Image m_plusBack;

	[SerializeField]
	private GameObject m_adText;

	private bool m_needUpdatePlusState;

	private void Start()
	{
		
		SpecBoostersModel specBoostersModel = WorkbookModel.Instance.SpecBoostersModel;
		specBoostersModel.OnBombModeChanged = (Action<SpecBoostersModel>)Delegate.Combine(specBoostersModel.OnBombModeChanged, new Action<SpecBoostersModel>(this.OnBombModeChangedHandler));
		SpecBoostersModel specBoostersModel2 = WorkbookModel.Instance.SpecBoostersModel;
		specBoostersModel2.OnStateChanged = (Action<SpecBoostersModel>)Delegate.Combine(specBoostersModel2.OnStateChanged, new Action<SpecBoostersModel>(this.OnBombCountChangedHandler));
		
		this.OnBombModeChangedHandler(WorkbookModel.Instance.SpecBoostersModel);
		this.OnBombCountChangedHandler(WorkbookModel.Instance.SpecBoostersModel);
		this.OnVideoAvailabilityChangedHandler();
		this.UpdateAdTextState();
	}

	private void Update()
	{
		if (this.m_needUpdatePlusState)
		{
			
			this.m_needUpdatePlusState = false;
			this.m_plus.SetActive(true);
				
			
			this.UpdateAdTextState();
		}
	}

	private void OnBombModeChangedHandler(SpecBoostersModel model)
	{
		this.m_activePointer.SetActive(model.BombMode);
	}

	private void OnBombCountChangedHandler(SpecBoostersModel model)
	{
		
		this.m_bombsCountField.text = model.BombCount.ToString();
		this.m_bombsCountFieldCopy.text = model.BombCount.ToString();
		this.OnVideoAvailabilityChangedHandler();
		
	}

	private void OnVideoAvailabilityChangedHandler()
	{
		
		this.m_needUpdatePlusState = true;
		
	}

	private void UpdateAdTextState()
	{
		
		this.m_adText.SetActive(false);
	}

	private void OnPurchaseHandler(bool res, SubscriptionType subscrType)
	{
		this.OnVideoAvailabilityChangedHandler();
		this.OnBombCountChangedHandler(WorkbookModel.Instance.SpecBoostersModel);
	}

	public void Click()
	{
		
		if (WorkbookModel.Instance.SpecBoostersModel.BombCount <= 0)
		{
			this.PlusClick();
		}
		else
		{
			WorkbookModel.Instance.SpecBoostersModel.ChangeBombMode(false);
			if (WorkbookModel.Instance.SpecBoostersModel.BombMode)
			{
				AnalyticsManager.Instance.BombClicked(WorkbookModel.Instance.SpecBoostersModel.BombCount);
			}
		}
	}

	public void PlusClick()
	{
		AnalyticsManager.Instance.BombAddClick(WorkbookModel.Instance.SpecBoostersModel.BombCount);
		
			WorkbookModel.Instance.SpecBoostersModel.AddBomb();
			WorkbookModel.Instance.SpecBoostersModel.ChangeBombMode(true);
		
	}

	public void CheatButtonClick()
	{
		WorkbookModel.Instance.SpecBoostersModel.AddBomb();
		WorkbookModel.Instance.SpecBoostersModel.AddBomb();
		WorkbookModel.Instance.SpecBoostersModel.AddBomb();
		WorkbookModel.Instance.SpecBoostersModel.AddBomb();
		WorkbookModel.Instance.SpecBoostersModel.AddBomb();
	}

	private void OnDestroy()
	{
		
	}
}


